package cn.yili12.server.client.handler;

import cn.yili12.server.client.vo.ClientMessage;
import cn.yili12.server.config.SystemProperties;
import cn.yili12.server.info.vo.InfoMessage;
import cn.yili12.server.info.vo.InfoMessageType;
import cn.yili12.server.mq.QueueProducer;
import com.alibaba.fastjson.JSON;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;


@Slf4j
public class BaseClientHandler {
    protected Channel channel;
    @Autowired
    protected QueueProducer producer;
    @Autowired
    protected SystemProperties properties;

    public void handler(ClientMessage message, Channel channel) {
        this.channel = channel;
        this.handler(message);
    }

    public void handler(ClientMessage message) {
        log.info("接收到消息：type={},no={},data={}", new Object[]{message.getType(), message.getNo(), message.getData()});
    }

    protected InfoMessage toInfoMessage(String data, String from, String to, String no, InfoMessageType type) {
        InfoMessage infoMessage = new InfoMessage();
        infoMessage.setData(data);
        infoMessage.setFrom(from);
        infoMessage.setNo(no);
        infoMessage.setTo(to);
        infoMessage.setType(type);
        return infoMessage;
    }
}
